package com.lagou.servlet;

import com.lagou.entity.ClassGrade;
import com.lagou.entity.Student;
import com.lagou.service.ClassGradeService;
import com.lagou.service.ClassGradeServiceImpl;
import com.lagou.service.StudentService;
import com.lagou.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "ClassGradeQueryServlet", urlPatterns = "/classGradeQueryServlet")
public class ClassGradeQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置编码方式， 解决中文乱码问题
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");

        // 1、获取前台得到的ids数据内容
        String idStr = request.getQueryString();
        idStr = idStr.replace("id=","");
        int id = Integer.parseInt(idStr);

        // 2、通过Service层实现对应功能
        ClassGradeService classGradeService = new ClassGradeServiceImpl();
        ClassGrade findClassGrade = classGradeService.classGradeFindService(id);
        System.out.println(findClassGrade);
        List<ClassGrade> classGradeList = new ArrayList<>();
        classGradeList.add(findClassGrade);
        request.getSession().setAttribute("classGradeList", classGradeList);
        response.sendRedirect("manageClassGrade.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
